package com.usian.admin.controller;

import com.usian.admin.service.AdChannelService;
import com.usian.api.admin.ChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.Path;
import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理" ,tags = "channel", description = "频道管理API")
public class AdChannelController implements ChannelControllerApi {
    @Autowired
    private AdChannelService adChannelService;
    @PostMapping("/list")
    @Override
    @ApiOperation(value = "查询频道",notes = "根据频道名称分页查询")
    @ApiImplicitParam(name = "dtos",type = "ChannelDto" ,value = "查询名称")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return adChannelService.findByNameAndPage(dto);
    }
    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody AdChannel adChannel) {
        return adChannelService.insert(adChannel);
    }
    @PostMapping("/update")
    @Override
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.update(adChannel);
    }
    @GetMapping("/del/{id}")
    @Override
    public ResponseResult delete(@PathVariable Integer id) {
        return adChannelService.delete(id);
    }

    @Override
    @GetMapping("channels")
    public ResponseResult findAll() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }
}
